package org.zch.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.zch.common.ApiResult;
import org.zch.service.FileService;

/**
 * 文件类
 *
 * @Author 刘新
 * @Date 2024/1/3 16:44
 */
@RestController
@RequestMapping("/file")
@Api(tags = "文件操作")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * 上传文件
     *
     * @param file 文件
     * @return
     */
    @ApiOperation(value = "上传文件", notes = "上传文件")
    @PostMapping("/upload")
    public ApiResult upload(MultipartFile file){
        return ApiResult.ok(fileService.upload(file));
    }


    /**
     * 删除文件
     *
     * @param fileName 文件名
     * @return
     */
    @ApiOperation(value = "删除文件", notes = "删除文件")
    @PostMapping("/deleteByName")
    public ApiResult upload(@RequestParam("fileName") String fileName){
        return ApiResult.ok(fileService.deleteByName(fileName));
    }
}
